﻿using Autofac;
using Quartz;
using Quartz.Spi;
using System;

namespace GitSyncApp.Services
{
    public class JobFactory : IJobFactory
    {
        private readonly ILifetimeScope lifetimeScope;

        public JobFactory(ILifetimeScope lifetimeScope)
        {
            this.lifetimeScope = lifetimeScope;
        }

        public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
        {
            return lifetimeScope.Resolve(bundle.JobDetail.JobType) as IJob;
        }

        public void ReturnJob(IJob job)
        {
            (job as IDisposable)?.Dispose();
        }
    }
}
